package com.wc.AlgoOJ_homework.ALOJ模块测试Ⅲ.F_糖果;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/5/20 17:22
 * @description http://43.138.190.70:8888/p/LQ1004?tid=66444686c0c2f98e569f403b
 */
public class Main {
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 110, M = 1 << 20;
    static int[] a = new int[N];
    static int[] f = new int[M];
    static int n, m, k;

    public static void main(String[] args) {
        n = sc.nextInt();
        m = sc.nextInt();
        k = sc.nextInt();
        for (int i = 1; i <= n; i++) {
            int x = 0;
            for (int j = 1; j <= k; j++) {
                x |= 1 << (sc.nextInt() - 1);
            }
            a[i] = x;
        }
        for (int i = 0; i < 1 << m; i++) f[i] = n + 1;
        f[0] = 0;
        for (int i = 0; i < 1 << m; i++) {
            for (int j = 1; j <= n; j++) {
                f[i | a[j]] = Math.min(f[i | a[j]], f[i] + 1);
            }
        }
        out.println(f[(1 << m) - 1] == n + 1 ? -1 : f[(1 << m) - 1]);
        out.flush();
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}
